import java.sql.Connection;
import java.util.Hashtable;

import marquee.xmlrpc.XmlRpcServer;
import marquee.xmlrpc.handlers.ReflectiveInvocationHandler;

public class GameServer extends ReflectiveInvocationHandler {

	Hashtable<Integer, StickFigure> players = new Hashtable<Integer, StickFigure>();

	Hashtable<String, Integer> privatePlayerIds = new Hashtable<String, Integer>();

	Hashtable<String, Integer> publicPlayerIds = new Hashtable<String, Integer>();

	Hashtable<Integer, Integer> privateToPublicPlayerIdMap = new Hashtable<Integer, Integer>();

	public static Connection conn = null;

	// returns a private player id
	public int createPlayer(String playerName) {

		if (!privatePlayerIds.containsKey(playerName)) {

			int privatePlayerId = (int) (Math.random() * 1000000);
			privatePlayerIds.put(playerName, privatePlayerId);

			int publicPlayerId = (int) (Math.random() * 1000000);
			publicPlayerIds.put(playerName, publicPlayerId);

			privateToPublicPlayerIdMap.put(privatePlayerId, publicPlayerId);

			return privatePlayerId;

		}

		return -1;

	}

	public void setPlayerPos(int privatePlayerId, double xPos, double yPos) {
	}

	public void setPlayerDirection(int privatePlayerId, double direction) {
	}

	public void setPlayerKeyState(int privatePlayerId, int keyCode, boolean state) {
	}

	public void damageOtherPlayer(int publicPlayerId, int damage) {
	}

	public void damageSelf(int privatePlayerId, int damage) {
	}

	public void createBullet(int privatePlayerId, double xPos, double yPos,
			double direction, double velocity) {
	}

	public static void main(String[] args) {
		GameServer gs = new GameServer();

		try {

			XmlRpcServer server = new XmlRpcServer();
			server.registerInvocationHandler("gameServer", gs);
			server.runAsService(13337);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
